package com.songlanyun.modules.account.controller.api;

import java.util.Arrays;
import java.util.Map;

import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.common.validator.group.AddGroup;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.account.model.dto.UserThirdIdentityDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.account.entity.UserThirdIdentityEntity;
import com.songlanyun.modules.account.service.UserThirdIdentityService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 会员在第三方平台中的身份（如果在小程序中的openid）
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-04 10:36:59
 */
@RestController
@RequestMapping("api/account/userthirdidentity")
public class UserThirdIdentityApiController extends AbstractApiController {
    @Autowired
    private UserThirdIdentityService userThirdIdentityService;


    /**
     * 信息
     */
    @GetMapping("/info")
    public R info() {
        UserThirdIdentityEntity userThirdIdentity = userThirdIdentityService.getById(getUserId(false));

        return R.ok().put("data", userThirdIdentity);
    }

    /**
     * 绑定
     */
    @PostMapping("/binding")
    public R binding(@RequestBody UserThirdIdentityDTO dto) {
        ValidatorUtils.validateEntity(dto, AddGroup.class);
        userThirdIdentityService.binding(getUserId(true), dto);

        return R.ok();
    }

    /**
     * 解绑
     */
    @PostMapping("/unbind")
    public R unbind(@RequestBody UserThirdIdentityDTO dto) {
        ValidatorUtils.validateEntity(dto, UpdateGroup.class);
        userThirdIdentityService.unbind(getUserId(true), dto);

        return R.ok();
    }

}
